@extends("layouts.backend.webadmin")
@section('page-header')
    <h1>
        <small>新增应用</small>
    </h1>
@endsection

@section('content')
<link rel="stylesheet" href="{{env('APP_ROOT')}}/assets/select2/css/select2.min.css">
<link rel="stylesheet" href="{{env('APP_ROOT')}}/assets/select2/css/select2totree.css">
    <!-- Main content -->
    <section class="content">
        <div class="row">
            <div class="col-xs-12">
                <div class="box">
                    <div class="box-body">
                        @if($errors->any())
                            <ul class="alert alert-danger">
                                @foreach($errors->all() as $error)
                                    <li>{{ $error }}</li>
                                @endforeach
                            </ul>
                        @endif
                            <form action="{{route('qyapp.update')}}" method="post">
                                <input type="hidden" title="id" name="id" value="{{$row['id']}}">
                                    <div class="form-group">
                                        <label for="parent-ogz">机构</label><br/>
                                        <select class="form-control" id="parent-ogz" name="ogz_id">
                                            @foreach($ogzs as $item)
                                            <option @if($item->id==$row['ogz_id']) selected @endif value="{{$item->id}}">{{$item->name}}</option>
                                            @endforeach
                                        </select>
                                        <input type="hidden" name="old_ogz_id" value="@if(old('ogz_id')){{old('ogz_id')}} @else {{$row['ogz_id']}}@endif ">
                                    </div>
                                    <div class="form-group">
                                        <label for="menuname">名称</label>
                                        <input value="@if(old('name')){{old('name')}} @else {{$row['name']}} @endif" type="text" class="form-control" id="name" placeholder="名称" name="name">
                                    </div>
                                    <div class="form-group">
                                        <label for="description">描述</label>
                                        <input value="@if(old('description')){{old('description')}} @else {{$row['description']}} @endif" type="text" class="form-control" id="description" placeholder="描述" name="description">
                                    </div>

                                    <div class="form-group">
                                        <label for="parent-user">联系人</label><br/>
                                        <select style="width: 100%;" multiple="multiple" class="form-control user-multiple" id="parent-user" name="user_id[]">

                                            <option value="0">--请选择--</option>
                                            @foreach($users as $user)
                                                @if(!empty(old('pcp')))
                                                    @foreach(old('pcp') as $pcId)
                                                        <option @if($pcId==$user->id) selected @endif  value="{{$user->id}}">{{$user->name}}</option>
                                                    @endforeach
                                                @elseif(!empty($row['user_id']))
                                                    @foreach(explode(',',$row['user_id']) as $pcId)
                                                                <option @if($pcId==$user->id) selected @endif  value="{{$user->id}}">{{$user->name}}</option>
                                                    @endforeach

                                                @else
                                                <option @if($user->id == $row['user_id']) selected @endif value="{{$user->id}}">{{$user->name}}</option>
                                                @endif
                                            @endforeach
                                        </select>
                                    </div>
                                <div class="form-group">
                                    <label for="uet">用户量预估<span>（单位：万）</span></label>
                                    <input value="@if(old('uet')){{old('uet')}} @else {{$row['uet']}} @endif" type="text" class="form-control" id="uet" placeholder="用户量预估" name="uet">
                                </div>
                                <div class="form-group">
                                    <label for="type">应用类型</label><br/>
                                    <select style="width: 100%;" class="form-control" id="type" name="type">

                                        <option value="0">--请选择--</option>
                                        @foreach($type as $id => $val)
                                            <option @if($id==old('type') || $id==$row['type']) selected @endif value="{{$id}}">{{$val}}</option>
                                        @endforeach

                                    </select>
                                </div>
                                <div class="form-group">
                                    <label for="is_foreign">是否对外</label><br/>
                                    <select style="width: 100%;" class="form-control" id="is_foreign" name="is_foreign">

                                        <option value="0">--请选择--</option>
                                        @foreach($is_foreign as $id => $val)
                                            <option @if($id==old('is_foreign') || $id==$row['is_foreign']) selected @endif value="{{$id}}">{{$val}}</option>
                                        @endforeach

                                    </select>
                                </div>
                                <div class="form-group">
                                    <label for="etv">预估系统价值<span>（单位：万）</span></label>
                                    <input value="@if(old('etv')){{old('etv')}} @else {{$row['etv']}} @endif" type="text" class="form-control" id="etv" placeholder="预估系统价值" name="etv">
                                </div>
                                <div class="form-group">
                                    <label for="address">域名/IP地址</label>
                                    <textarea type="text" class="form-control" id="address" placeholder="域名/IP地址" name="address">@if(old('address')){{old('address')}} @else {{$row['address']}} @endif</textarea>
                                </div>
                                <div class="form-group">
                                    <label for="ops">开放端口和服务</label>
                                    <textarea type="text" class="form-control" id="ops" placeholder="开放端口和服务" name="ops">@if(old('ops')){{old('ops')}} @else {{$row['ops']}} @endif</textarea>
                                </div>
                                <div class="form-group">
                                    <label for="msv">中间件和服务及版本信息</label>
                                    <textarea type="text" class="form-control" id="msv" placeholder="中间件和服务及版本信息" name="msv">@if(old('msv')){{old('msv')}} @else {{$row['msv']}} @endif</textarea>
                                </div>
                                <div class="form-group">
                                    <label for="lvv">开发语言和使用第三方库及版本信息</label>
                                    <textarea type="text" class="form-control" id="lvv" placeholder="开发语言和使用第三方库及版本信息" name="lvv">@if(old('lvv')){{old('lvv')}} @else {{$row['lvv']}} @endif</textarea>
                                </div>
                                <div class="form-group">
                                    <label for="ut">测试账号</label>
                                    <textarea type="text" class="form-control" id="ut" placeholder="测试账号" name="ut">@if(old('ut')){{old('ut')}} @else {{$row['ut']}} @endif</textarea>
                                </div>
                                {!! csrf_field() !!}
                                <input type="submit" class="btn btn-primary" value="确认">
                            </form>
                        <input type="hidden" name="ogzs" value="{{$ogzsJson}}">
                    </div>
                </div>
            </div>
        </div>
    </section>
@stop
@section('javascript-end')
<script src="{{env('APP_ROOT')}}/assets/layui/layui.all.js"></script>
<script src="{{env('APP_ROOT')}}/assets/select2/js/select2.min.js"></script>
<script src="{{env('APP_ROOT')}}/assets/select2/js/select2totree.js"></script>
<script src="{{env('APP_ROOT')}}/assets/select2/js/i18n/zh-CN.js"></script>
<script src="{{env('APP_ROOT')}}/js/common.js"></script>
    <script>
        $(function () {
            var m1 = manage();
            //组织机构
            var ogzs = $.parseJSON($('input[name="ogzs"]').val());
            $('#parent-ogz').select2ToTree({language:'zh-CN'});
            $('#parent-ogz').html(m1.eachSelect(ogzs,'ogz',$('input[name="old_ogz_id"]').val()));
            //多选联系人
            $('.user-multiple').select2();
        });
    </script>
@endsection